#include "array.h"
#include "sparse.h"
#include "parser.h"
#include "vp.h"
#include <getopt.h>
#include <cstdio>
#include <cstdlib>

using namespace std;

int main(int argc, char* argv[]) {
    Array<svector*> s;
    perceptron vp;
    real radius = 100;
    int norm = 2;
    const char* modelfile = "vpmodel";
    int t = 10;
    int option;
    const char* help = "Usage: %s [ -m modelfile ] [ -n norm ] [ -r radius ]  [ -t iterations ] trainset\n";
    while ((option = getopt(argc, argv, "m:n:r:t:")) != EOF) {
        switch (option) {
            case 'm':
                modelfile = optarg;
                break;
            case 'n':
                norm = atoi(optarg);
                break;
            case 'r':
                radius = atof(optarg);
                break;
            case 't':
                t = atoi(optarg);
                break;
            case '?':
                fprintf(stderr, help, argv[0]);
                exit(1);
                break;
        }
    }
    if (argv[optind] == 0) {
        fprintf(stderr, help, argv[0]);
        exit(1);
    }
    parser p(argv[optind]);
    p.parse(s);
    vp.set(norm, radius);
    vp.train(s, t);
    vp.write(modelfile);
    return 0;
}
